use std::env;

use ane_system::dao::{Dept, DeptDo, Role, User};
use sea_orm::{Database, DbConn};

async fn get_db() -> DbConn {
    dotenv::dotenv().ok();
    let databaseurl = env::var("DATABASEURL").unwrap();
    Database::connect(databaseurl).await.unwrap()
}

#[tokio::main]
#[test]
async fn test() {
    let db = get_db().await;
    ane_system::Mutation::init_db(&db).await.unwrap();
}

#[tokio::main]
#[test]
async fn test_user() {
    let conn = get_db().await;
    let user = User::list(&conn, 0, 3, Some(1), None, None).await.unwrap();
    let s = User::get_detail_by_id(&conn, 1).await.unwrap();
    let s = User::fetch_resource(&conn, 1).await.unwrap();
    println!(" {s:?}")
}

#[tokio::main]
#[test]
async fn test_role() {
    let conn = get_db().await;
    Role::list(&conn, 0, 50).await.unwrap();
    let res = ane_system::casbin_policies(&conn, None, None)
        .await
        .unwrap();
    println!("{res:?}");
}

#[tokio::main]
#[test]
async fn test_dept() {
    let conn = get_db().await;
    let dept = DeptDo {
        parent_id: Some(7),
        dept_name: "Ane".to_owned(),
        phone: Some("1515****190".to_owned()),
        email: Some("lthee12@hotmail.com".to_owned()),
        description: None,
        order_num: Some(0),
        status: true,
    };
    Dept::update(&conn, 6, dept).await.unwrap();
    let tree = Dept::get_tree(&conn, 1, false).await.unwrap();
    println!("{tree:#?}");
}
